package com.ebupt.migu.common.push;

import org.apache.kafka.common.serialization.Deserializer;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author liuyangyang@e-byte.com
 * @description: TODO
 * @date 2024/8/17 18:52
 */
public class PushTopicDeserializer implements Deserializer<PushTopicBean> {
    /**
     * Deserialize a record value from a byte array into a value or object.
     *
     * @param topic topic associated with the data
     * @param data  serialized bytes; may be null; implementations are recommended to handle null by returning a value or
     *              null rather than throwing an exception.
     * @return deserialized typed data; may be null
     */
    @Override
    public PushTopicBean deserialize(String topic, byte[] data) {
        try {
            if (data == null) {
                return null;
            }
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.readValue(data, PushTopicBean.class);
        } catch (Exception e) {
            throw new IllegalArgumentException("Error deserializing MyMessage", e);
        }
    }
}
